import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/7 15:43
 * @description 广度优先遍历
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
    }
    public int getImportance(List<Employee> employees, int id) {
        int ans = 0;
        Map<Integer, Employee> map = new HashMap<>();
        for(Employee e: employees) {
            map.put(e.id, e);
        }
        Queue<Employee> queue = new ArrayDeque<>();
        queue.add(map.get(id));
        while (!queue.isEmpty()) {
            Employee e = queue.poll();
            List<Integer> sub = e.subordinates;
            for (Integer i: sub) {
                queue.add(map.get(i));
            }
            ans += e.importance;
        }
        return ans;
    }
}
